{createAction} = require('redux-actions')

actions =
  getListStart:createAction('SCDZQZ/GET_LIST_START')
  getListCompleted:createAction('SCDZQZ/GET_LIST_COMPLETED')
  refreshListStart:createAction('SCDZQZ/REFRESH_LIST_START')
  refreshListCompleted:createAction('SCDZQZ/REFRESH_LIST_COMPLETED')
  modifyListItem:createAction('SCDZQZ/MODIFY_LISTITEM')
  fetchRefreshList:(token)->
    debugger
    (dispatch)->
      dispatch actions.refreshListStart()
      fetch("http://202.136.214.173/api/PilotWorkSearch?pageNum=1",{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers:
            'Content-Type':'application/x-www-form-urlencoded'
            token:token
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        res.json()
      .then (json)->
        date = new Date()
        dispatch actions.refreshListCompleted
          list:json
          lastFetchTime:date
      .catch (err)->
        console.log(err)


  fetchGetList:(token,pageNum)->
    debugger
    (dispatch)->
      dispatch actions.getListStart()
      fetch("http://202.136.214.173/api/PilotWorkSearch?pageNum=#{pageNum}",{
          method: 'GET'
          mode: 'cors'
          cache: 'default'
          headers:
            'Content-Type':'application/x-www-form-urlencoded'
            token:token
          # body:"pageNum=#{pageNum}&state=1"
        })
      .then (res)->
        res.json()
      .then (json)->
        date = new Date()
        dispatch actions.getListCompleted
          list:json
          lastFetchTime:date
      .catch (err)->
        console.log(err)

module.exports = actions


# {createAction} = require('redux-actions')
# {fetchLogOut} = require('./userInfo.js')
# fetchRefreshListStart = createAction('SCDZQZ/REFRESH_LIST_START')
# fetchRefreshList = (token)->
#       do createAction "SCDZQZ/REFRESH_LIST",->
#                           promise = fetch 'http://202.136.214.173/api/v_short_pilotcallback?pageNum=1',{
#                             method: 'GET'
#                             mode: 'cors'
#                             cache: 'default'
#                             headers: {
#                               'Content-Type':'application/x-www-form-urlencoded'
#                               token:token
#                             }
#                           }
#                           promise.type = 'token'
#                           promise
# module.exports = {
#   fetchRefreshListStart,
#   fetchRefreshList
# }
